<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title></title>
	<script src="./js/vue.js" type="text/javascript" charset="utf-8"></script>
    <script src="js/mui.min.js"></script>
    <link href="css/mui.min.css" rel="stylesheet"/>
	<style>
		#app{
			text-align: center;
			margin-top: 20px;
		}
		[v-cloak]{
			display: none;
		}
	</style>
</head>
<body>
	<header class="mui-bar mui-bar-nav">
		<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		<h1 class="mui-title">自定义指令</h1>
	</header>
	<div class="mui-content" id="app" v-cloak>
		<div class="main" v-clickoutside="handleClose">
			<button type="button" @click="show = !show">点击显示下拉菜单</button>
			<div class="dropdown" v-show="show">
				<p>下拉框的内容, 点击外面区域可以关闭</p>
			</div>
		</div>
	</div>
	<script type="text/x-template" id="tempID">
		<div>
			组件内容
		</div>
	</script>
	<script type="text/javascript">
		Vue.directive('clickoutside',{
			bind:function(el,binding,vnode){
				function documentHandler (e){
					
					if(el.contains(e.target)){
						return false; 
					}
					
					if(binding.expression){
						binding.value(e)
					}
					
					el.__vueClickOutside__ = documentHandler; 
					document.addEventListener('click',documentHandler);
				}
			},
			unbind:function(el,binding){
				document.removeEventListener('click', el.__vueClickOutside__); 
				delete el.__vueClickOutside__
			}
		})
		var vm = new Vue({
			el:"#app",
			data:{
				show:false
			},
			methods:{
				handleClose:function(){
					this.show  = false;
				}
				
			}
		}) 
	</script>
</body>
</html>